package com.example.mapper;

import com.example.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/*
* 员工管理
* */
@Mapper
public interface EmpMapper {

    /*查询总记录数*/

    @Select("select count(*) from tlias.emp")
    public Integer count();


    /*
    * 当方法里里面有参数 要用void 没有参数就不用
    * */
    @Select("select * from tlias.emp limit #{start},#{pageSize}") //起始索引
    List<Emp> page(Integer start, Integer pageSize);

    //使用PageHelper插件完成
    @Select("select * from tlias.emp")
    public List<Emp> list1();

    //带有条件的分页查询 复杂sql需要XML文件
    public  List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);

    //批量删除
    void deletes(ArrayList<Integer> list2);

    //新增员工
    @Insert("insert into tlias.emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
            " VALUES (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void inset(Emp emp);

    //根据id查询员工
    @Select("select * from tlias.emp where  id = #{id}")
    Emp deleteid(Integer id);


    //修改员工--此修改只能 必须要全部修改 所有要用到XML文件
    @Update("update tlias.emp set " +
            "image =#{image},username = #{username},name= #{name},gender = #{gender},job = #{job},entrydate = #{entrydate}, update_time =#{updateTime},dept_id = #{deptID}" +
            " where id = #{id}")
    void update1(Emp emp);

    //修改员工 xml
    void  update2(Emp emp);

    //根据姓名和密码查询员工
    @Select("select * from tlias.emp where username = #{username} and password = #{password}")
    Emp getByUSernameAndPosseord(Emp emp);

    //删除部门下的所有成员
    @Delete("delete from tlias.emp where dept_id = #{deptId}")
    void deleteemp(Integer dept_id);
}
